package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.JingXuanBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 首页——喜欢视频
 */
public class HomeLikeVediosAdapter extends BaseQuickAdapter<JingXuanBean, BaseViewHolder> {
    private int type = 1;//1视频，2书籍

    public HomeLikeVediosAdapter(int layoutResId, List<JingXuanBean> data) {
        super(layoutResId, data);
    }
    @Override
    public int getItemCount() {
        int count = 0;
        if(mData!=null){
            if(type==2){
                count = mData.size()>3?3:mData.size();
            }else{
                count = mData.size()>4?4:mData.size();
            }
        }
        return count;
    }
    @Override
    protected void convert(BaseViewHolder baseViewHolder, JingXuanBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.iv_video_pic);
        baseViewHolder.setText(R.id.tv_title, item.getTitle());
//        baseViewHolder.setText(R.id.tv_price,);
        TextView tvPrice = baseViewHolder.getView(R.id.tv_price);
        tvPrice.setVisibility(View.GONE);

        ImageView ivVideoPlay = baseViewHolder.getView(R.id.iv_play);
        TextView tvTitle = baseViewHolder.getView(R.id.tv_title);
        tvTitle.setMinLines(1);
        tvTitle.setMaxLines(1);
        TextView tvTime = baseViewHolder.getView(R.id.tv_time_long);
        tvTime.setText(item.getDuration());

        FrameLayout.LayoutParams picParams = (FrameLayout.LayoutParams) ivPic.getLayoutParams();
        LinearLayout.LayoutParams rootParams = (LinearLayout.LayoutParams) baseViewHolder.getView(R.id.ll_root).getLayoutParams();
        if (type == 2) {//视频
            ivVideoPlay.setVisibility(View.VISIBLE);
            tvTime.setVisibility(View.VISIBLE);
            picParams.width = (DisplayUtil.getDensityWdith(mContext)-DisplayUtil.dip2px(mContext, 50))/3;
            picParams.height = picParams.width*9 / 16;
        } else {//书籍
            ivVideoPlay.setVisibility(View.INVISIBLE);
            tvTime.setVisibility(View.INVISIBLE);
            picParams.width = (DisplayUtil.getDensityWdith(mContext) - DisplayUtil.dip2px(mContext, 60)) / 4;
            picParams.height = picParams.width *14 / 13;
            if(baseViewHolder.getLayoutPosition()==0){
                rootParams.leftMargin = 0;
            }else {
                rootParams.leftMargin = DisplayUtil.dip2px(mContext, 10);
            }
        }
        rootParams.width = picParams.width;
        ImageLoadingUtil.loadImgGlideRoundCenterCrop(ivPic, item.getImg());
    }

    public void setType(int type1) {
        type = type1;
    }
}
